/*
 * Copyright (C) 2011-2013 Eric Lasota
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#ifndef __RDX_PROCESSING_HPP__
#define __RDX_PROCESSING_HPP__

#include "rdx_basictypes.hpp"
#include "rdx_gcslots.hpp"
#include "rdx_callbacks.hpp"

namespace RDX
{
	struct OperationContext;
	
	template<class _Tvalue> class StaticLookupPODKey;
	template<class _Tkey, class _TlookupType> class StaticLookupTable;


	namespace Programmability
	{
		struct RuntimeThread;
		class String;
		struct Type;
		struct StructuredType;
	};

	namespace IO
	{
		struct ITextDeserializer;
		struct IFileStream;
	};

	namespace ObjectManagement
	{
		struct IObjectManager;
		struct IPackageHost;
		struct Package;

		struct INativeTypeHost
		{
			virtual void SetTypeProperties(IObjectManager *objm, Programmability::StructuredType *st) const = 0;
			virtual Programmability::NativeCallback HookMethod(const Programmability::String *str) const = 0;
		};

		struct ISerializer
		{
			// Marks a dependency.  If this returns true, then the object should be serialized
			virtual bool TryIncludeObject(const void *obj) = 0;
			virtual void SerializeReference(void *obj) = 0;
			virtual void SerializeBulk(const void *data, LargeInt sz) = 0;
			virtual void SerializeData(Programmability::Type *type, const void *data) = 0;
		};

		// Type processors are for processing types out
		// They should always be static
		struct ITypeProcessor
		{
			virtual void MarkDependencies(IObjectManager *objm, void *obj, const Programmability::StructuredType *st, bool markNative, ISerializer *ser, ScanID scanID, RDX::ObjectManagement::GCLink gcl) const = 0;
			virtual void Finalize(void *obj, IObjectManager *objm) const = 0;
			virtual bool OnLoad(OperationContext *ctx, void *obj, IObjectManager *objm) const = 0;
		};

		typedef StaticLookupTable<StaticLookupPODKey<const GCInfo *>, LargeInt> SSIDTable;

		struct ITypeSerializer
		{
			virtual void DeserializeTextInstance(OperationContext *ctx, IObjectManager *objm, void *instance, IO::ITextDeserializer *td, IPackageHost *host, Package *pkg) const = 0;
			virtual void DeserializeBinaryInstance(OperationContext *ctx, IObjectManager *objm, void *instance, IO::IFileStream *reader, IPackageHost *host, Package *pkg) const = 0;

			virtual void SerializeBinaryInstance(IObjectManager *objm, const void *obj, IO::IFileStream *fs, const ObjectManagement::SSIDTable *ssidTable) const = 0;
			virtual void SerializeTextInstance(IObjectManager *objm, const void *obj, IO::IFileStream *fs, const ObjectManagement::SSIDTable *ssidTable) const = 0;
		};
	}
}

#endif

